package com.spring.sunflower.common

import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.blankj.utilcode.util.SPUtils
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.spring.sunflower.R
import com.spring.sunflower.bean.TaskAwardDailyBean
import com.spring.sunflower.constant.Constant
import com.spring.sunflower.util.DateTimeUtils
import java.util.*

/**
 * Created by Kevin on 2021/8/28<br/>
 *
 * Describe:<br/>
 */
class AwardDailyAdapter(layoutResId: Int, data: MutableList<TaskAwardDailyBean.DatasBean>) :
    BaseQuickAdapter<TaskAwardDailyBean.DatasBean, BaseViewHolder>(layoutResId, data) {
    var gender = "1"

    init {
        gender = SPUtils.getInstance().getString(Constant.KEY_GENDER, "1")
    }

    override fun convert(holder: BaseViewHolder, item: TaskAwardDailyBean.DatasBean) {
        item?.let {
            holder.setText(R.id.tvTitle, "${item.taskName} 奖励")
            val timeFormatText = DateTimeUtils.getTimeFormatText(Date((item.updateTime).toLong()))
            holder.setText(R.id.tvTime, timeFormatText)
            val tvDetail = holder.getView<TextView>(R.id.tvDetail)
            tvDetail.setText("+${item.award}")
            tvDetail.setTextColor(ContextCompat.getColor(context, R.color.colorPrimary))
        }
        val ivAward = holder.getView<ImageView>(R.id.ivMoney)
        Glide.with(context)
            .load(if ("1" == gender) R.drawable.ic_money else R.drawable.ic_income_diamond)
            .placeholder(R.drawable.ic_placeholder)
            .into(ivAward)
    }
}